home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / src / gdb-4.12 / gdb / ch-typep.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-03  |  8.7 KB  |  313 lines

  1. /* Support for printing Chill types for GDB, the GNU debugger.
  2.    Copyright 1986, 1988, 1989, 1991 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "defs.h"
  21. #include "obstack.h"
  22. #include "bfd.h"        /* Binary File Description */
  23. #include "symtab.h"
  24. #include "gdbtypes.h"
  25. #include "expression.h"
  26. #include "value.h"
  27. #include "gdbcore.h"
  28. #include "target.h"
  29. #include "command.h"
  30. #include "gdbcmd.h"
  31. #include "language.h"
  32. #include "demangle.h"
  33. #include "ch-lang.h"
  34. #include "typeprint.h"
  35.  
  36. #include <string.h>
  37. #include <errno.h>
  38.  
  39. static void
  40. chill_type_print_base PARAMS ((struct type *, GDB_FILE *, int, int));
  41.  
  42. void
  43. chill_print_type (type, varstring, stream, show, level)
  44.      struct type *type;
  45.      char *varstring;
  46.      GDB_FILE *stream;
  47.      int show;
  48.      int level;
  49. {
  50.   if (varstring != NULL && *varstring != '\0')
  51.     {
  52.       fputs_filtered (varstring, stream);
  53.       fputs_filtered (" ", stream);
  54.     }
  55.   chill_type_print_base (type, stream, show, level);
  56. }
  57.  
  58. /* Print the name of the type (or the ultimate pointer target,
  59.    function value or array element).
  60.  
  61.    SHOW nonzero means don't print this type as just its name;
  62.    show its real definition even if it has a name.
  63.    SHOW zero means print just typename or tag if there is one
  64.    SHOW negative means abbreviate structure elements.
  65.    SHOW is decremented for printing of structure elements.
  66.  
  67.    LEVEL is the depth to indent by.
  68.    We increase it for some recursive calls.  */
  69.  
  70. static void
  71. chill_type_print_base (type, stream, show, level)
  72.      struct type *type;
  73.      GDB_FILE *stream;
  74.      int show;
  75.      int level;
  76. {
  77.   char *name;
  78.   register int len;
  79.   register int i;
  80.   struct type *index_type;
  81.   struct type *range_type;
  82.   LONGEST low_bound;
  83.   LONGEST high_bound;
  84.  
  85.   QUIT;
  86.  
  87.   wrap_here ("    ");
  88.   if (type == NULL)
  89.     {
  90.       fputs_filtered ("<type unknown>", stream);
  91.       return;
  92.     }
  93.  
  94.   /* When SHOW is zero or less, and there is a valid type name, then always
  95.      just print the type name directly from the type. */
  96.  
  97.   if ((show <= 0) && (TYPE_NAME (type) != NULL))
  98.     {
  99.       fputs_filtered (TYPE_NAME (type), stream);
  100.       return;
  101.     }
  102.  
  103.   check_stub_type (type);
  104.  
  105.   switch (TYPE_CODE (type))
  106.     {
  107.       case TYPE_CODE_PTR:
  108.     if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_VOID)
  109.       {
  110.         fprintf_filtered (stream, "PTR");
  111.         break;
  112.       }
  113.     fprintf_filtered (stream, "REF ");
  114.     chill_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
  115.     break;
  116.  
  117.       case TYPE_CODE_BOOL:
  118.     fprintf_filtered (stream, "BOOL");
  119.     break;
  120.  
  121.       case TYPE_CODE_ARRAY:
  122.     range_type = TYPE_FIELD_TYPE (type, 0);
  123.     index_type = TYPE_TARGET_TYPE (range_type);
  124.     low_bound = TYPE_FIELD_BITPOS (range_type, 0);
  125.     high_bound = TYPE_FIELD_BITPOS (range_type, 1);
  126.         fputs_filtered ("ARRAY (", stream);
  127.     print_type_scalar (index_type, low_bound, stream);
  128.     fputs_filtered (":", stream);
  129.     print_type_scalar (index_type, high_bound, stream);
  130.     fputs_filtered (") ", stream);
  131.     chill_print_type (TYPE_TARGET_TYPE (type), "", stream, show, level);
  132.     break;
  133.  
  134.       case TYPE_CODE_BITSTRING:
  135.         fprintf_filtered (stream, "BOOLS (%d)",
  136.               TYPE_FIELD_BITPOS (TYPE_FIELD_TYPE(type,0), 1) + 1);
  137.     break;
  138.  
  139.       case TYPE_CODE_SET:
  140.         fputs_filtered ("POWERSET ", stream);
  141.     chill_print_type (TYPE_FIELD_TYPE (type, 0), "", stream,
  142.               show - 1, level);
  143.     break;
  144.  
  145.       case TYPE_CODE_STRING:
  146.     range_type = TYPE_FIELD_TYPE (type, 0);
  147.     index_type = TYPE_TARGET_TYPE (range_type);
  148.     high_bound = TYPE_FIELD_BITPOS (range_type, 1);
  149.         fputs_filtered ("CHARS (", stream);
  150.     print_type_scalar (index_type, high_bound + 1, stream);
  151.     fputs_filtered (")", stream);
  152.     break;
  153.  
  154.       case TYPE_CODE_MEMBER:
  155.     fprintf_filtered (stream, "MEMBER ");
  156.         chill_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
  157.     break;
  158.       case TYPE_CODE_REF:
  159.     fprintf_filtered (stream, "/*LOC*/ ");
  160.         chill_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
  161.     break;
  162.       case TYPE_CODE_FUNC:
  163.     fprintf_filtered (stream, "PROC (?)");
  164.         chill_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
  165.     break;
  166.  
  167.       case TYPE_CODE_STRUCT:
  168.     if (chill_is_varying_struct (type))
  169.       {
  170.         chill_type_print_base (TYPE_FIELD_TYPE (type, 1),
  171.                    stream, show, level);
  172.         fputs_filtered (" VARYING", stream);
  173.       }
  174.     else
  175.       {
  176.         fprintf_filtered (stream, "STRUCT ");
  177.  
  178.         fprintf_filtered (stream, "(\n");
  179.         if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0))
  180.           {
  181.         if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
  182.           {
  183.             fprintfi_filtered (level + 4, stream, "<incomplete type>\n");
  184.           }
  185.         else
  186.           {
  187.             fprintfi_filtered (level + 4, stream, "<no data fields>\n");
  188.           }
  189.           }
  190.         else
  191.           {
  192.         len = TYPE_NFIELDS (type);
  193.         for (i = TYPE_N_BASECLASSES (type); i < len; i++)
  194.           {
  195.             struct type *field_type = TYPE_FIELD_TYPE (type, i);
  196.             QUIT;
  197.             print_spaces_filtered (level + 4, stream);
  198.             if (TYPE_CODE (field_type) == TYPE_CODE_UNION)
  199.               { int j; /* variant number */
  200.             fputs_filtered ("CASE OF\n", stream);
  201.             for (j = 0; j < TYPE_NFIELDS (field_type); j++)
  202.               { int k; /* variant field index */
  203.                 struct type *variant_type
  204.                   = TYPE_FIELD_TYPE (field_type, j);
  205.                 int var_len = TYPE_NFIELDS (variant_type);
  206.                 print_spaces_filtered (level + 4, stream);
  207.                 if (strcmp (TYPE_FIELD_NAME (field_type, j),
  208.                     "else") == 0)
  209.                   fputs_filtered ("ELSE\n", stream);
  210.                 else
  211.                   fputs_filtered (":\n", stream);
  212.                 if (TYPE_CODE (variant_type) != TYPE_CODE_STRUCT)
  213.                   error ("variant record confusion");
  214.                 for (k = 0; k < var_len; k++)
  215.                   {
  216.                 print_spaces_filtered (level + 8, stream);
  217.                 chill_print_type (TYPE_FIELD_TYPE (variant_type, k),
  218.                           TYPE_FIELD_NAME (variant_type, k),
  219.                           stream, show - 1, level + 8);
  220.                 if (k < (var_len - 1))
  221.                   fputs_filtered (",", stream);
  222.                 fputs_filtered ("\n", stream);
  223.                   }
  224.               }
  225.             fputs_filtered ("ESAC\n", stream);
  226.               }
  227.             else
  228.               chill_print_type (field_type,
  229.                     TYPE_FIELD_NAME (type, i),
  230.                     stream, show - 1, level + 4);
  231.             if (i < (len - 1))
  232.               {
  233.             fputs_filtered (",", stream);
  234.               }
  235.             fputs_filtered ("\n", stream);
  236.           }
  237.           }
  238.         fprintfi_filtered (level, stream, ")");
  239.       }
  240.     break;
  241.  
  242.       case TYPE_CODE_RANGE:
  243.     if (TYPE_DUMMY_RANGE (type))
  244.       chill_type_print_base (TYPE_TARGET_TYPE (type),
  245.                  stream, show, level);
  246.     else if (TYPE_TARGET_TYPE (type))
  247.       {
  248.         chill_type_print_base (TYPE_TARGET_TYPE (type),
  249.                    stream, show, level);
  250.         fputs_filtered (" (", stream);
  251.         print_type_scalar (TYPE_TARGET_TYPE (type),
  252.                    TYPE_FIELD_BITPOS (type, 0), stream);
  253.         fputs_filtered (":", stream);
  254.         print_type_scalar (TYPE_TARGET_TYPE (type),
  255.                    TYPE_FIELD_BITPOS (type, 1), stream);
  256.         fputs_filtered (")", stream);
  257.       }
  258.     else
  259.       fprintf_filtered (stream, "RANGE? (%s : %d)",
  260.                 TYPE_FIELD_BITPOS (type, 0),
  261.                 TYPE_FIELD_BITPOS (type, 1));
  262.     break;
  263.  
  264.       case TYPE_CODE_ENUM:
  265.     {
  266.       register int lastval = 0;
  267.       fprintf_filtered (stream, "SET (");
  268.       len = TYPE_NFIELDS (type);
  269.       for (i = 0; i < len; i++)
  270.         {
  271.           QUIT;
  272.           if (i) fprintf_filtered (stream, ", ");
  273.           wrap_here ("    ");
  274.           fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
  275.           if (lastval != TYPE_FIELD_BITPOS (type, i))
  276.         {
  277.           fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i));
  278.           lastval = TYPE_FIELD_BITPOS (type, i);
  279.         }
  280.           lastval++;
  281.         }
  282.       fprintf_filtered (stream, ")");
  283.     }
  284.     break;
  285.  
  286.       case TYPE_CODE_VOID:
  287.       case TYPE_CODE_UNDEF:
  288.       case TYPE_CODE_ERROR:
  289.       case TYPE_CODE_UNION:
  290.       case TYPE_CODE_METHOD:
  291.     error ("missing language support in chill_type_print_base");
  292.     break;
  293.  
  294.       default:
  295.  
  296.     /* Handle types not explicitly handled by the other cases,
  297.        such as fundamental types.  For these, just print whatever
  298.        the type name is, as recorded in the type itself.  If there
  299.        is no type name, then complain. */
  300.  
  301.     if (TYPE_NAME (type) != NULL)
  302.       {
  303.         fputs_filtered (TYPE_NAME (type), stream);
  304.       }
  305.     else
  306.       {
  307.         error ("Unrecognized type code (%d) in symbol table.",
  308.            TYPE_CODE (type));
  309.       }
  310.     break;
  311.       }
  312. }
  313.